package wxutil

import (
	"context"
	"time"

	"zhonghui/console/warehouse/dbx/cache_main"
	"zhonghui/console/warehouse/helperx"
)

func mpAccessTokenKey(appId string) string {
	return "mp_access_token_key_prefix" + helperx.EasyMD5(appId)
}

func GetMpAccessToken(appId string) (string, error) {
	return cache_main.Client().Get(context.Background(), mpAccessTokenKey(appId)).Result()
}

func SetMpAccessToken(appId, token string) error {
	return cache_main.Client().Set(context.Background(), mpAccessTokenKey(appId), token, time.Second*6000).Err()
}

func GetMpAccessTokenTtl(appId string) (time.Duration, error) {
	return cache_main.Client().TTL(context.Background(), mpAccessTokenKey(appId)).Result()
}
